package com.qdu.servlet;

import com.qdu.entity.Movie;
import com.qdu.service.MovieService;
import com.qdu.service.impl.MovieServiceImpl;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 作为首页用的servlet，运行程序会先运行该servlet，查询所有电影，然后再转到index.jsp页面显示所有电影基本信息
 * 
 * @author Anna
 */
@WebServlet("/gams")
public class GetAllMoviesServlet extends HttpServlet {

    MovieService movieService=new MovieServiceImpl();
    
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //1. 因为查询所有电影，无需请求参数，所以不获取请求参数
        
        //2. 执行业务逻辑 
        List<Movie> list=movieService.findAllMovies(); //查询所有电影的信息
        
        //3. 生成动态响应
        //将电影列表作为一个属性添加到请求对象中，转发请求共享给index.jsp页面
        req.setAttribute("all_movies", list); 
        req.getRequestDispatcher("/movie_list2.jsp").forward(req, resp);
    }
}
